package com.byxm.wlgw.service;


import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

import com.byxm.wlgw.bean.SpxhBean;
import com.byxm.wlgw.common.DataBaseAccess;
import com.byxm.wlgw.query.SpxhQuery;

public class SpxhService {
	SpxhQuery spxhQuery=new SpxhQuery();
	public List<SpxhBean> getSpxh(int splbfid) throws Exception{
		String sql = spxhQuery.getSpxhSql(splbfid);
		DataBaseAccess dba=null;
		List<SpxhBean> list=new ArrayList<SpxhBean>();
		try {
			dba = new DataBaseAccess();
			ResultSet rs = dba.executeQuery(sql);
			while (rs.next()) {	
				SpxhBean spxh=new SpxhBean();
				spxh.setXhid(rs.getInt("xhid"));
				spxh.setSpxhnr(rs.getString("spxhnr"));
				spxh.setPx(rs.getInt(splbfid));
				spxh.setPx(rs.getInt("px"));
				list.add(spxh);
				}
			rs.close();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally{
			dba.releaseConnect();
		}
		return list;
	}
	/**
	 * 保存商品型号
	 * @param spxhBean
	 * @return
	 * @throws Exception
	 */
	
	public boolean saveSpxh(SpxhBean spxhBean) throws Exception{
		DataBaseAccess dba=null;
		int iFlag=0;
		try {
			dba =new DataBaseAccess();
			iFlag=dba.executeUpdate(spxhQuery.getSaveSql(spxhBean));
			dba.commit();
		} catch (Exception e) {
			dba.rollback();
			e.printStackTrace();
		}finally{
			dba.releaseConnect();
		}
		if(iFlag>0){
			return true;
		}else{
			return false;
		}
	}
	public boolean deleteSpxh(int xhid) throws Exception{
		DataBaseAccess dba=null;
		int iFlag=0;
		
		try {
			dba=new DataBaseAccess();
			iFlag=dba.executeUpdate(spxhQuery.deleteSql(xhid));
	        dba.commit();
		} catch (Exception e) {
			dba.rollback();
			e.printStackTrace();
		}finally{
			dba.releaseConnect();
		}
		if(iFlag>0)
		{
			return true;
		}else{
			return false;
		}
	}
}


